<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://www.skysz.com/framework" prefix="skysz"%>

<s:i18n name="com/skysz/framework/package">
	<table width="100%" height="100%">
		<tr>
			<td style="padding: 3px;" valign="top">
				<table width="100%" height="100%">
					<tr>
						<td class="layout_win_bar_query">
							<div style="float: left">
								顾客信息（手机号码： 卡号）
							</div>
							<div id="mr.pay.paymain.handler"
								style="background-image: url('../resource/images/div_${param.defaultQueryMode}.gif')"
								class="div_tool_right"
								onclick="skysz.utils.divOpenOrClose('mr.pay.paymain.handler','mr.pay.paymain.form',	mr.pay.paymain.grid)"
								class="div_open">
							</div>

							<div
								style="background-image: url('../resource/images/tool_save.gif')"
								class="div_tool_right"
								title="<s:text name='fw.query.storecondition' />"
								onclick="mr.pay.paymain.form.saveQuery()">
							</div>
							<div
								style="background-image: url('../resource/images/tool_find.gif')"
								class="div_tool_right"
								title="<s:text name='fw.query.selectcondition' />"
								onclick="mr.pay.paymain.form.listQuery()">
							</div>

						</td>

					</tr>
					<tr>
						<td class="tb_searchbar_container">
							<table class="tb_searchbar" id='mr.pay.paymain.form'
								cellspacing=1 cellpadding="4">
								<tr>
									<td class="td_title" width="10%">
										顾客手机号码
									</td>
									<td class="td_field" colspan="5">
									<skysz:gridInput
											imgId="mr.pay.paymain.gridSelector"
											id="mr.pay.paymain.form.phone" /> <input
										id="mr.pay.paymain.form.custId" type="hidden" />
										<skysz:gridselector
											id="mr.pay.paymain.gridSelector" idCol="id"
											quickQuery="mr.pay.paymain.form.phone"
											sqlkey="mr.pay.custQuery" title="手机号码"
											queryCols="phone,cardno" queryTexts="手机号码,卡号"
											hiddenCols="id"
											showCols="custname,cardno,cardname,phone,code,balance"
											showHeader="姓名,卡号,类型,手机,编号,余额/次"
											showColsType="ro,ro,ro,ro,ro,ro"
											targetCols="phone,id"
											targetIds="mr.pay.paymain.form.phone,mr.pay.paymain.form.custId"
											param="~mr.pay.paymain.queryCust()" /></td>
								</tr>

								<tr>
									<td class="td_title" width="10%">
										编号
									</td>
									<td class="td_field"  width="20%">
										<input id="mr.pay.paymain.form.code"
											readonly="readonly"  class="input_text">
									</td>
									<td class="td_title"  width="10%">
										卡号
									</td>
									<td class="td_field"  width="20%">
										<input id="mr.pay.paymain.form.cardNo" readonly="readonly"  class="input_text">
									</td>
									<td class="td_title"  width="10%">
										备注
									</td>
									<td class="td_field">
										<input id="mr.pay.paymain.form.remark" readonly="readonly"  class="input_text">
									</td>
								</tr>
							</table>
						</td>
					</tr>

					<tr height="70px;" >
						<td class="layout_win_grid">
							<table width="100%" height="100%" >
								<tr>
									<td >
										<div id="mr.pay.paymain.gridbox1" class="div_gridbox"></div>
									</td>
								</tr>
								<tr style="display: none;">
									<td id="mr.pay.paymain.pagingArea1" class="layout_win_bar_page"></td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<td class="layout_split_x"></td>
					</tr>
					<tr>
						<td class="layout_win_title">
							<div style="float: left">
								<s:text name='fw.list' />
							</div>
						</td>
					</tr>
					<tr>
						<td class="layout_win_menu">
							<div id="mr.pay.paymain.menu"></div>
						</td>
					</tr>
					<tr>
						<td class="layout_win_grid">
							<table width="100%" height="100%">
								<tr>
									<td>
										<div id="mr.pay.paymain.gridbox" class="div_gridbox"></div>
									</td>
								</tr>
								<tr>
									<td id="mr.pay.paymain.pagingArea"
										class="layout_win_bar_page"></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

<c:url var="findAll" value="/mr/pay/payAction.action">
	<c:param name="method" value="findAll"></c:param>
</c:url>	
<c:url var="findCardList" value="/mr/pay/payAction.action">
	<c:param name="method" value="findCardList"></c:param>
</c:url>
<c:url var="loadCustByPhone" value="/mr/pay/payAction.action">
	<c:param name="method" value="loadCustByPhone"></c:param>
</c:url>
	
<script type="text/javascript">				
skysz.namespace("mr.pay.paymain");
skysz.onReady(function(){
	var isDefaultQuery = ${param.isDefaultQuery};
	var  form = new skysz.form('mr.pay.paymain.form');
	mr.pay.paymain.form = form;
	mr.pay.paymain.form.initQuery() ;
	
	var grid1 = new dhtmlXGridObject('mr.pay.paymain.gridbox1');
	mr.pay.paymain.grid1 = grid1;
	grid1.setImagePath("../dhtmlx/dhtmlxGrid/imgs/");
	grid1.setHeader("序号,类型,名称,余额,次数,总欠款,开卡日期,截止日期");
	grid1.setInitWidths("50,120,120,110,80,110,110,110");
	grid1.setColAlign("center,left,left,right,right,right,center,center");
	grid1.setColTypes("ro,ro,ro,rmb,ro,rmb,date,date");
	grid1.setColSorting("na,na,na,na,na,na,na,na");
	//plineGrid.enableAutoHeigth(true);
 	grid1.skyinit(); 
	grid1.enablePaging("mr.pay.paymain.pagingArea1","mr.pay.paymain.grid1");
	grid1.loadEmpty();
	
	var grid = new dhtmlXGridObject('mr.pay.paymain.gridbox');
	grid.setImagePath("../dhtmlx/dhtmlxGrid/imgs/");
	grid.setHeader("序号,项目类型,项目名称,原价,折扣,现价,数量,合计,操作");
	grid.setInitWidths("50,110,110,100,100,100,100,100,130");
	grid.setColAlign("center,left,left,right,right,right,right,right,center");
	grid.setColTypes("ro,ro,ro,rmb,ro,rmb,ro,rmb,ro");
	grid.setColSorting("na,na,na,na,na,na,na,na,na");
 	grid.skyinit(); 
	grid.enablePaging("mr.pay.paymain.pagingArea","mr.pay.paymain.grid");
	if(isDefaultQuery){ 
		grid.loadEmpty();
		//grid.clearAndLoadpage("${findAll}", form.getQueryString());
	} else {
		grid.loadEmpty();
	}
	
	

	var menu = new dhtmlXMenuObject("mr.pay.paymain.menu");
	menu.setIconsPath("../resource/images/");
	menu.attachEvent("onClick", menuClick);
	var xmlString = "<menu><item id='mr.pay.paymain.add' img='add.gif' text='开单'></item><item id='mr.pay.paymain.add1' img='add.gif' text='散客/非持卡客户开单'></item><item id='mr.pay.paymain.delete' text='清空单' img='delete.gif'></item></menu>";
	menu.loadXMLString(xmlString) ;
	function menuClick(id) {
		if(id == 'mr.pay.paymain.add'){
			payOpen();
		}else if (id == "mr.pay.paymain.delete") {
			grid1.setRowHidden("1",true);
		} else if (id == "mr.pay.paymain.add1") {
			grid1.setRowHidden("1",false);
		}
		return true;
	}
	
	function phoneChange() {
		var phone = skysz.$("mr.pay.paymain.form.phone").value;
		if( phone ) {
			var cust = skysz.ajax.postSync("${loadCustByPhone}","phone="+phone);
			if( cust ) {
				skysz.$("mr.pay.paymain.form.code").value = cust.code;
				skysz.$("mr.pay.paymain.form.cardNo").value = cust.cardNo;
				skysz.$("mr.pay.paymain.form.remark").value = cust.remark;
			}
			grid1.clearAndLoadpage("${findCardList}", "phone="+phone);
		} else {
			skysz.$("mr.pay.paymain.form.code").value = "";
			skysz.$("mr.pay.paymain.form.cardNo").value = "";
			skysz.$("mr.pay.paymain.form.remark").value = "";
			grid1.loadEmpty();
		}
	}
	//监听手机号码变更
	var lis = new skysz.utils.ValueListener("mr.pay.paymain.form.custId",phoneChange);
	
	function payOpen() {
		var phone = skysz.$("mr.pay.paymain.form.phone").value;
		if (! phone ) {
			skysz.msg.info("请输入或选择顾客手机号，散客或非持卡顾客请点击'散客/非持卡客户开单'按钮进行开单。");
			return false;
		}
		
		var url = "../mr/pay/payOpen.jsp?phone="+phone+"&win=mr.pay.paymain.window&grid=mr.pay.paymain.grid";
		mr.pay.paymain.window = skysz.window.modalWindow("开单买单 》开单",800,600, url);
	}
	
	function doSubmit() {
		var id = grid.getSelectedId();
		if(! id ) {
			skysz.msg.info("请选择要提交审批的数据。");
			return;
		}else if(id.split(",").length > 1 ) {
			skysz.msg.info("提交审批不能多选。");
			return false;
		}
		skysz.ajax.post("${submit}","id="+id,postCallBack)
	}
	
	
	function toDelete() {
		var id = grid.getSelectedId();
		if(! id ) {
			skysz.msg.info("请选择要删除的数据。");
			return;
		}else if(id.split(",").length > 1 ) {
			skysz.msg.info("删除不能多选。");
			return false;
		}
		skysz.msg.confirm("是否要删除选择的数据。",doDelete);
	}
	
	function doDelete(msg) {
		if( msg == skysz.msg.YES) {
			var id = grid.getSelectedId();
			skysz.ajax.post("${delete}","id="+id,postCallBack)
		}
	}
	
	var postActionResponse = {};
	function postCallBack(actionResponse) {
		if(skysz.msg.isReturnBack(postActionResponse,actionResponse)){		
			grid.refreash();
 			skysz.ajax.destroyActionResponse(postActionResponse);
 		}
	}
	
	mr.pay.paymain.form.select  = function(isHidden){
		var amount = skysz.$("mr.pay.paymain.form.payAmount").value;
		if( amount != "" && isNaN(amount) ) {
			skysz.msg.info("金额必须是一个数字，请重新输入。");
			return false;
		}
		if(isHidden){
			skysz.utils.divOpenOrClose('mr.pay.paymain.handler','mr.pay.paymain.form',mr.pay.paymain.grid) ;
		}
		var pars = form.getQueryString() ;
 		grid.clearAndLoadpage("${findAll}", pars);
	} 
	
	mr.pay.paymain.queryCust = function () {
		var s='l.cardtype_=2';
		return  s;
	};

	function init() {
		mr.pay.paymain.grid = grid;
	}
	init();
 	 
});
	
</script>
</s:i18n>
